package com.ee.chat.admin.controller.materialmanage;

import com.ee.chat.admin.service.IVersionService;
import com.ee.chat.common.bean.Result;
import com.ee.chat.common.entity.SysVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("version")
public class VersionController {
    private Logger log = LoggerFactory.getLogger(VersionController.class);

    @Resource
    IVersionService versionService;

    /**
     * app版本列表
     * @Author Shane
     * @Date 2019/12/18 17:25
     * @param
     * @return
     **/
    @RequestMapping("list")
    public Result list(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit,
                       Integer type, String time){
        try {
            return versionService.list(request, page, limit, type, time);
        } catch (Exception e){
            log.error("【获取app版本列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新状态
     * @Author Shane
     * @Date 2019/12/18 18:29
     * @param
     * @return
     **/
    @RequestMapping("updateStatus")
    public Result updateStatus(HttpServletRequest request, @RequestParam Integer id, @RequestParam Integer status){
        try {
            return versionService.updateStatus(request, id, status);
        } catch (Exception e){
            log.error("【更新app版本状态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 保存app
     * @Author Shane
     * @Date 2019/12/19 10:10
     * @param
     * @return
     **/
    @RequestMapping("save")
    public Result save(HttpServletRequest request, SysVersion sysVersion){
        try {
            return versionService.save(request, sysVersion);
        } catch (Exception e){
            log.error("【保存app版本错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 跳转到编辑app
     * @Author Shane
     * @Date 2019/12/19 10:41
     * @param
     * @return
     **/
    @RequestMapping("toEdit")
    public Result toEdit(HttpServletRequest request, Integer id){
        try {
            return versionService.toEdit(request, id);
        } catch (Exception e){
            log.error("【跳转编辑app错误】", e);
        }
        return Result.returnFailure();
    }
}
